<template>
  <div>
    <div class="shopCartWrapper">
      <div class="billingFooterBasket">
        <div class="basketItem" v-if="selectNumbers <=0 ">
          <img src="~img/icon_kaidan_gouwuche_n.png">
        </div>
        <div
          class="basketItem shopCartItem"
          v-if="selectNumbers > 0"
          @click.stop.prevent="showCartList"
        >
          <img src="~img/icon_gouwulan_s.png">
          <div class="shopCartRange" v-show="selectNumbers>0">{{selectNumbers}}</div>
        </div>
        <div class="shopCartSum" :class="[selectNumbers > 0 ? 'hasSum' : '']">
          <em style="font-size: 0.28rem;margin-right:0.1rem;">¥</em>
          {{selectSum}}
        </div>
      </div>
      <div class="billingFooterSelled">挂单</div>
      <div class="billingFooterSelled billingFooterSubmit">结算</div>
    </div>
    <transition
      name="mask-fade"
      enter-active-class="animated fadeIn"
      leave-active-class="animated fadeOut"
    >
      <div class="list-mask" v-show="foldState" @click="closMask"></div>
    </transition>
    <transition name="fold">
      <div class="select-list" v-show="foldState">
        <div class="select-header">
          <span>已选商品</span>
          <div class="select-clear" @click="clearCart">清空</div>
        </div>
        <div class="select-goods-wrapper">
          <Scroll :data="selectGoods" :refreshDelay="refreshDelay" ref="selectGoods">
            <div class="select-goodsList">
              <div class="select-goodsList-item" v-for="(good,index) in selectGoods" :key="index">
                <div class="select-goodsList-name">{{good.Title}}</div>
                <div class="select-goodsList-price">
                  <em style="font-size: 0.24rem;">￥</em>
                  {{good.MemberPrice}}
                </div>
                <div class="select-goodsList-action">
                  <Cartcontrol :food="good" style="top:50%;left:0;margin-top:-0.2rem;"></Cartcontrol>
                </div>
              </div>
            </div>
          </Scroll>
        </div>
      </div>
    </transition>
  </div>
</template>
<script>
import {
  Confirm,
  Alert,
  Toast,
  Notify,
  Loading
} from "vue-ydui/dist/lib.rem/dialog";
import Scroll from "@/components/common/scroll";
import Cartcontrol from "@/components/common/cartcontrol";
export default {
  props: {
    shopGood: {
      type: Object
    },
    selectGoods: {
      type: Array
    },
    selectNumbers: {
      type: Number
    },
    selectSum: {
      type: Number
    }
  },
  components: {
    Scroll,
    Cartcontrol
  },
  data() {
    return {
      foldState: false,
      refreshDelay: 120
    };
  },
  methods: {
    showCartList() {
      this.foldState = !this.foldState;
    },
    clearCart() {
      Confirm({
        title: "提示",
        mes: "确定要清空购物车吗？",
        opts: () => {
          this.selectGoods.forEach(item => {
            item.count = 0;
          });
        }
      });
    },
    closMask() {
      this.foldState = false;
    }
  },
  watch: {
    foldState() {
      if (this.foldState) {
        setTimeout(() => {
          this.$refs.selectGoods.refresh();
        }, 20);
      }
    },
    selectGoods() {
      if (this.selectGoods.length == 0) {
        this.foldState = false;
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.shopCartWrapper {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 1rem;
  display: flex;
  z-index: 200;
  .billingFooterBasket {
    display: flex;
    justify-items: center;
    align-items: center;
    height: 100%;
    width: 3.5rem;
    background-color: #434343;
    .basketItem {
      margin-left: 0.4rem;
      width: 0.74rem;
      height: 0.74rem;
      background-color: #4a4a4a;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      img {
        width: 0.56rem;
      }
      &.shopCartItem {
        position: relative;
        .shopCartRange {
          position: absolute;
          right: -0.1rem;
          top: -0.08rem;
          width: 0.3rem;
          height: 0.3rem;
          background-color: #ff5355;
          border-radius: 50% 50%;
          color: #fff;
          font-size: 12px;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }
    }
    .shopCartSum {
      display: flex;
      align-items: center;
      justify-content: baseline;
      height: 100%;
      color: #999999;
      font-size: 0.42rem;
      margin-left: 0.2rem;
      &.hasSum {
        color: #eabe7d;
      }
    }
  }
  .billingFooterSelled {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    height: 100%;
    width: 2rem;
    background-color: #ffc13b;
    font-size: 0.36rem;
  }
  .billingFooterSubmit {
    @extend .billingFooterSelled;
    background-color: #ff5355;
  }
}
.list-mask {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  transition: all 0.5s;
  background: rgba(7, 17, 27, 0.6);
  backdrop-filter: blur(10px);
  opacity: 1;
  &.mask-fade-enter-active,
  &.mask-fade-leave-active {
    transition: all 0.3s;
  }
  &.mask-fade-enter,
  &.mask-fade-leave-to {
    opacity: 0;
  }
}
.select-list {
  display: flex;
  flex-direction: column;
  position: fixed;
  width: 100%;
  height: 4.7rem;
  background-color: #ffffff;
  transform: translate3d(0, -100%, 0);
  z-index: 11;
  &.fold-enter-active,
  &.fold-leave-active {
    transition: all 0.4s;
  }
  &.fold-enter,
  &.fold-leave-to {
    transform: translate3d(0, 0, 0);
  }
  .select-header {
    padding: 0 0.3rem;
    display: flex;
    align-items: center;
    height: 0.8rem;
    background-color: #e1e1e1;
    justify-content: space-between;
    span {
      font-size: 0.24rem;
      font-weight: normal;
      font-stretch: normal;
      color: #666666;
    }
    .select-clear {
      display: flex;
      align-items: center;
      font-size: 0.24rem;
      font-weight: normal;
      font-stretch: normal;
      letter-spacing: 0px;
      color: #999999;
      height: 100%;
      padding-left: 0.37rem;
      background-image: url(~img/icon_kaidan_qingkong.png);
      background-repeat: no-repeat;
      background-size: 0.22rem 0.26rem;
      background-position: 0.1rem center;
    }
  }
  .select-goods-wrapper {
    position: relative;
    width: 100%;
    height: 3.9rem;
    // overflow-x: hidden;
    // overflow-y: scroll;
  }
  .select-goodsList {
    width: 100%;
    display: flex;
    flex-direction: column;
    .select-goodsList-item {
      display: flex;
      padding: 0 0.3rem;
      align-items: center;
      justify-content: space-between;
      height: 1rem;
      box-shadow: 0 -1px 0 #e1e1e1 inset;
      .select-goodsList-name {
        width: 1.8rem;
        font-size: 0.28rem;
        font-weight: normal;
        font-stretch: normal;
        letter-spacing: 0px;
        color: #333333;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .select-goodsList-price {
        width: 1.8rem;
        display: flex;
        align-items: center;
        color: #999999;
        font-size: 0.32rem;
        justify-content: center;
      }
      .select-goodsList-action {
        position: relative;
        width: 1.4rem;
        height: 100%;
      }
    }
  }
}
</style>


